package com.itheima.Thread.多线程的两种方式;

public class Demo {
    public static void main(String[] args) throws InterruptedException {
    //基于Thread类方式实现多线程
        MyThread t1 = new MyThread("张三");
        //设置线程优先级
        t1.setPriority(2);
        t1.start();

        //基于MyRannable接口方式实现多线程
        //先创建一个线程任务
        MyRunnable mr = new MyRunnable();
        //创建一个线程对象
        Thread t2 = new Thread(mr, "李四");
        t2.setPriority(10);
        t2.start();

        Thread.sleep(20);

        //基于Lambda表达式方式快速实现多线程
        new Thread(()->{
            for (int i = 0; i < 20; i++) {
                System.out.println(Thread.currentThread().getName()+"lambda来实现多线程");
            }
        },"赵六").start();
    }
}


class MyThread extends Thread{
    public MyThread() {
    }

    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 30; i++) {
            System.out.println(getName()+" 继承Thread类 " +i);
        }

    }
}

class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+" 实现Runnable "+i);
        }
    }
}